
package com.thor.palmmall.dao.statement.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.util.converter.OperateInfoConverter;
import com.thor.palmmall.api.statement.AStatementPayBill;
import com.thor.palmmall.api.statement.AStatementPayBillDetail;
import com.thor.palmmall.dao.statement.PStatementPayBill;
import com.thor.palmmall.dao.statement.PStatementPayBillDetail;

public class PStatementPayBillConverter implements Converter<PStatementPayBill, AStatementPayBill> {

  public static PStatementPayBillConverter getInstance() {
    if (instance == null)
      instance = new PStatementPayBillConverter();
    return instance;
  }

  private static PStatementPayBillConverter instance;

  private PStatementPayBillConverter() {
  }

  @Override
  public AStatementPayBill convert(PStatementPayBill source) {
    if (source == null) {
      return null;
    }
    AStatementPayBill target = new AStatementPayBill();
    target.inject(source);
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setActionTime(source.getActionTime());
    target.setAmount(source.getAmount());
    target.setBillNumber(source.getBillNumber());
    target.setCreateInfo(OperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target.setLastModifyInfo(OperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setMethod(source.getMethod());
    target.setState(source.getState());
    target.setRemark(source.getRemark());
    target.setTransactioNo(source.getTransactioNo());
    target.setBuyerLogonId(source.getBuyerLogonId());
    target.setBuyerPayAmount(source.getBuyerPayAmount());
    target.setInvoiceAmount(source.getInvoiceAmount());
    target.setReceiptAmount(source.getReceiptAmount());
    target.setSellerEmail(source.getSellerEmail());
    target.setErrMsg(source.getErrMsg());
    target.setNotifyFlag(source.getNotifyFlag());
    target.setPaymentType(source.getPaymentType());
    target.setAlipayPublicKey(source.getAlipayPublicKey());
    target.setBillId(source.getBillId());
    target.setSyncedErrorMsg(source.getSyncedErrorMsg());
    target.setProductName(source.getProductName());
    List<AStatementPayBillDetail> details = new ArrayList<AStatementPayBillDetail>();
    if (source.getDetails() != null) {
      for (PStatementPayBillDetail detail : source.getDetails()) {
        details.add(StatementPayBillDetailConverter.getInstance().convert(detail));
      }
    }
    target.setDetails(details);
    target.setVerifyFilePath(source.getVerifyFilePath());
    target.setSignFilePath(source.getSignFilePath());
    target.setSignFilePwd(source.getSignFilePwd());
    target.setSignCertType(source.getSignCertType());
    target.setCommissionCharge(source.getCommissionCharge());
    target.setTryCount(source.getTryCount());
    target.setMaxCount(source.getMaxCount());
    return target;
  }

}
